<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>_出库任务分配</title>
<script type="text/javascript">
   //指派任务
	function task(taskId){
	
	  var btn_id="#btn_"+taskId;
	  var worker_id="#worker_"+taskId;
	  var status_id="#status_"+taskId;
	  var commander_id="#commander_"+taskId;
	  
	  var jobuuid=$(worker_id).val();

	  if(jobuuid==''){
	    alert("请选择执行人");
	    $(worker_id).focus();
	    return;
	  }
	  
	  $.ajax({
			type : 'post',
			url : '${ctx}/allotAudit/ajaxTask',
			data : {
				jobuuid : jobuuid,
				taskId : taskId
			},
			dataType : 'json',
			success : function(data) {
			    var msg=data.msg;
				if (msg == "success") {
					 alert("任务指派成功！");
					 $(btn_id).attr("disabled", true);
	                 $(btn_id).attr("class", "btn");
	                 $(btn_id).val("已指派");
	                 $(worker_id).attr("disabled", true);
	                 $(status_id).html("任务待执行...");
					 $(commander_id).html('${curUser.realname}');
				}else if(msg=="token"){
				    alert("此任务已被分配。");
				    location.reload();
				}else {
					alert("网络繁忙，请稍后重试...");
				}
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
	  
	  
	  
	  
	}
</script>
</head>

<body>

    <c:if test="${not empty message}">
		<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
	</c:if>

	<div style="height: 10px;"></div>
	
	<!-- 任务列表 -->
	<table class="table table-striped table-bordered table-condensed" style="width: 95%; margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="9" bgcolor="#8EB4CB">任务分配列表</th>
		</thead>
		<tr>
			<th style="width: 100px;">出库类型</th>
			<th style="width: 120px;">任务批次号</th>
			<th style="width: 100px;">商家</th>
			<th style="width: 120px;">sku</th>
			<th style="width: 100px;">拣货数量</th>
			<th style="width: 100px;">指派人</th>
			<th style="width: 100px;">执行人</th>
			<th style="width: 80px;">任务状态</th>
			<th style="width: 100px;">操作</th>
		</tr>
		
		<c:forEach items="${taskList}" var="task">
		<tr >
		   <td>
		     <c:if test="${task.batch.outType eq '1'}">调拨出库</c:if>
		     <c:if test="${task.batch.outType eq '2'}">销售出库</c:if>
		   </td>
		   <td>${task.taskBatch}</td>
		   <td>${task.customerCode}</td>
		   <td>${task.sku}</td>
		   <td>${task.num}</td>
		   <td id="commander_${task.id}" >${task.commander.realname}</td>
		   <td>
			   <select  id="worker_${task.id}" <c:if test="${task.status ne '0'}">disabled=disabled</c:if>  style="width: 130px;">
					<option value="">请选择员工...</option> 
					<c:forEach items="${userList}" var="user">
						<option value="${user.jobuuid}"
						  <c:if test="${ (task.worker ne null) && (task.worker.jobuuid eq user.jobuuid) }" >selected=selected</c:if>
						>${user.realname}</option>
					</c:forEach>
				</select> 
		   </td>
		   
		   <td id="status_${task.id}">
		      <c:if test="${task.status eq '0'}">任务未指派</c:if>
		      <c:if test="${task.status eq '1'}">任务待执行...</c:if>
		      <c:if test="${task.status eq '3'}">任务完成</c:if>
		      <c:if test="${task.status eq '4'}">任务完成(有异常)</c:if>
		   </td>
		   <td>
		     <c:if test="${task.status eq '0'}">
		       <input class="btn btn-info" type="button" value="指派" id="btn_${task.id}" onclick="task('${task.id}');" />
		     </c:if>
		     <c:if test="${task.status ne '0'}">
			     <c:if test="${task.commandType eq '1'}">
			       <input class="btn" type="button" value="已指派" disabled="disabled" />
			     </c:if>
			     <c:if test="${task.commandType eq '2'}">
			       <input class="btn" type="button" value="已领取" disabled="disabled" />
			     </c:if>
		      </c:if>
		   </td>
		</tr>
		</c:forEach>

	</table>
	
	<div class="form-actions">
		<a href="${ctx}/allotAudit" class="btn btn-info" >返回</a>
	</div>


</body>
</html>
